package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.BusinessStatusConstants;
import com.qk.domain.business.BusinessDO;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessListDTO;
import com.qk.dto.business.HighSeaPoolDTO;
import com.qk.dto.business.UpdateBusinessInfoDTO;
import com.qk.entity.Business;
import com.qk.management.service.BusinessService;
import com.qk.management.service.CustomerService;
import com.qk.vo.business.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


@RestController
@RequestMapping("/businesses")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @GetMapping
    public Result queryList(BusinessListDTO dto) {
        PageResult<BusinessDO> pageResult = businessService.queryList(dto);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result addBusiness(@RequestBody BusinessDTO dto) {
        businessService.addBusiness(dto);
        return Result.success();
    }

    @PutMapping("/assign/{businessId}/{userId}")
    public Result updateBusinessById(@PathVariable Long businessId, @PathVariable Long userId) {
        businessService.updateById(Business.builder()
                .id(businessId.intValue())
                .userId(userId.intValue())
                .updateTime(LocalDateTime.now())
                .status(BusinessStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping("{id}")
    public Result getBusinessInfoById(@PathVariable Integer id) {
        BusinessVO businessVO = businessService.getBusinessInfoById(id);
        return Result.success(businessVO);
    }

    @PutMapping
    public Result updateBusinessInfo(@RequestBody UpdateBusinessInfoDTO dto) {
        businessService.updateBusinessInfo(dto);
        return Result.success();
    }

    @PutMapping("back/{id}")
    public Result backBusiness(@PathVariable Integer id) {
        businessService.backBusiness(id);
        return Result.success();
    }

    @PostMapping("/toCustomer/{id}")
    public Result toCustomer(@PathVariable Integer id) {
        businessService.toCustomer(id);
        return Result.success();
    }
    @GetMapping("pool")
    public Result queryPoolBusiness(HighSeaPoolDTO dto) {
       PageResult<Business> pageResult = businessService.queryPoolBusiness(dto);
       return Result.success(pageResult);

    }




}